// pages/notice/notice.js
var regexp = require('../../utils/regexpUtil.js');
var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    groupId: '',
    hidden: false,
    group: {},
    sku:{},
    market:{},
    listings:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      groupId: options.groupId
    });
    this.getGroup();
    this.getListings();
  },
  //获取挂牌组信息
  getGroup:function(){
    var that = this;
    wx.request({
      url: getApp().globalData.host + 'webapp/listing/notice/' + this.data.groupId + '.html',
      header: getApp().globalData.header,
      success: function (res) {
        if (typeof (res.data) != 'undefined' && res.data.groupId != '') {
          //处理数据
          res.data.desc = regexp.regexpImg(res.data.desc)
          res.data.validTime = util.formatDate(res.data.validTime);
          res.data.expireTime = util.formatDate(res.data.expireTime);
          res.data.deliveryExpireTime = util.formatDate(res.data.deliveryExpireTime);
          res.data.noticeTime = util.formatDate(res.data.noticeTime);
          that.setData({
            group: res.data
          });
        }
      },
      complete:function(res){
        that.getSku();
        that.getMarket();
      }
    })
  },
  //获取挂牌SKU信息
  getSku:function(){
    let that = this;
    wx.request({
      url: getApp().globalData.host + 'webapp/resource/getSku.html',
      header: getApp().globalData.header,
      data:{'skuId':that.data.group.skuId},
      success: function (res) {
        if (typeof (res.data) != 'undefined' && res.data != '') {
          that.setData({
            sku: res.data,
            hidden: true            
          });
        }
      }
    })
  },
  //获取批次信息
  getListings:function(){
    let that = this;
    wx.request({
      url: getApp().globalData.host + 'listing/list',
      header: getApp().globalData.header,
      data: { 'groupId': that.data.groupId },
      method: 'POST',
      success: function (res) {
        if (typeof (res.data.records) != "undefined") {
          that.setData({
            listings: res.data.records
          })
        }
      },
      fail: function (res) { },
      complete: function (res) {
      }
    })
  },
  //
  getMarket:function(){
    let that = this;
    wx.request({
      url: getApp().globalData.host + 'webapp/business/getMarket.html',
      header: getApp().globalData.header,
      data:{'marketId':that.data.group.marketId},
      success: function (res) {
        if (typeof (res.data) != 'undefined' && res.data != '') {
          res.data.openTimeAM = util.formatSqlTime(res.data.openTimeAM);
          res.data.closeTimeAM = util.formatSqlTime(res.data.closeTimeAM);
          res.data.openTimePM = util.formatSqlTime(res.data.openTimePM);
          res.data.closeTimePM = util.formatSqlTime(res.data.closeTimePM);
          that.setData({
            market: res.data
          });
        }
      }
    })
  }
})